<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="提现人ID" prop="withdrawUserId">
        <el-input
          v-model="queryParams.withdrawUserId"
          placeholder="请输入提现人ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="manageList">
      <el-table-column label="序号" type="index" width="50" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现类型" align="center" prop="withdrawType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.withdraw_type" :value="scope.row.withdrawType"/>
        </template>
      </el-table-column>
      <el-table-column label="提现金额(分)" align="center" prop="withdrawMoney" />
      <el-table-column label="提现时间" align="center" prop="withdrawTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.withdrawTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现人ID" align="center" prop="withdrawUserId" />
      <el-table-column label="提现人昵称" align="center" prop="withdrawUserName" />
      <el-table-column label="所属APP" align="center" prop="appName" />
      <el-table-column label="提现前账户" align="center" prop="withdrawBeforeMoney" />
      <el-table-column label="提现后账户" align="center" prop="withdrawAfterMoney" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-check"
            @click="getVideoList(scope.row.withdrawUserId, scope.row.id)"
            v-hasPermi="['withdraw:manage:remove']"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="title" :visible.sync="open" width="1500px" append-to-body>
      <el-table v-loading="loading2" :data="VideoManageList">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" align="center" prop="id" />
        <el-table-column label="广告平台" align="center" prop="adPlatform">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.ad_name" :value="scope.row.adPlatform"/>
          </template>
        </el-table-column>
        <el-table-column label="所属APP" align="center" prop="appSource" />
        <el-table-column label="用户id" align="center" prop="userId" />
        <el-table-column label="用户昵称" align="center" prop="nickName" />
        <el-table-column label="所属代理id" align="center" prop="agencyId" />
        <el-table-column label="所属代理名称" align="center" prop="agencyName" />
        <el-table-column label="广告位id" align="center" prop="adId" :show-overflow-tooltip="true"/>
        <el-table-column label="ECPM" align="center" prop="ecpm" />
        <el-table-column label="预估收益(分)" align="center" prop="ecpmReality" />
        <el-table-column label="设备型号" align="center" prop="model" />
        <el-table-column label="设备ip" align="center" prop="ip" :show-overflow-tooltip="true" />
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit-outline"
              @click="addBlackList(scope.row)"
              v-hasPermi="['blacklist:list:add']"
            >加入黑名单</el-button>
          </template>

        </el-table-column>
      </el-table>

      <pagination
        v-show="total2>0"
        :total="total2"
        :page.sync="queryParams2.pageNum"
        :limit.sync="queryParams2.pageSize"
        @pagination="getVideoList(queryParams2.userId, shId)"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleDelete(shId)">审核通过</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title2" :visible.sync="open2" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="视频ID" hidden="hidden" >
          <el-input
            v-model="form.id"
          />
        </el-form-item>
        <el-form-item label="拉黑原因" prop="reason">
          <el-input
            maxlength="300"
            class="public-showWordLimit"
            type="textarea"
            v-model="form.reason"
            placeholder="请输入拉黑原因" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel2">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listManage, delManage } from "@/api/withdraw/manage";
import { addBlackList, listVideoManage } from '@/api/opearte/videomanage'

export default {
  // 提现审核
  name: "ManageSh",
  dicts: ['withdraw_type', 'ad_name'],
  data() {
    return {
      // 表单参数
      form: {},
      // 遮罩层
      loading: true,
      loading2: true,
      title: "视频明细",
      title2: "加入黑名单",
      // 是否显示弹出层
      open: false,
      open2: false,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total2: 0,
      // 提现管理表格数据
      manageList: [],
      VideoManageList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        withdrawStatus: 1,
        withdrawUserId: null,
      },
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
        userId: null
      },
      shId: null,
      // 表单校验
      rules: {
        reason: [
          { required: true, trigger: 'blur', message: '请输入拉黑原因' }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询提现管理列表 */
    getList() {
      this.loading = true;
      listManage(this.queryParams).then(response => {
        this.manageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getVideoList(withdrawUserId, id) {
      this.open = true;
      this.loading2 = true;
      this.shId = id;
      this.queryParams2.userId = withdrawUserId
      listVideoManage(this.queryParams2).then(response => {
        this.VideoManageList = response.rows;
        this.total2 = response.total;
        this.loading2 = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel2() {
      this.open2 = false;
      this.reset2();
    },
    reset() {
      this.shId= null;
      this.queryParams2 = {
        pageNum: 1,
        pageSize: 10,
        userId: null
      }
    },
    reset2() {
      this.form = {
        id: null,
        reason: null
      };
      this.resetForm("form");
    },
    addBlackList(row) {
      this.open2 = true;
      this.title = "加入黑名单"
      this.form.id=row.id;
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          addBlackList(this.form).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open2 = false;
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 删除按钮操作 */
    handleDelete(id) {
      const ids = id;
      this.$modal.confirm('是否确认审核通过？').then(function() {
        return delManage(ids);
      }).then(() => {
        this.open = false;
        this.getList();
        this.$modal.msgSuccess("审核通过");
      }).catch(() => {});
    },
  }
};
</script>
